<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <title>产品价格配置</title>
    <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css" media="all">
</head>
<style type="text/css">
    .layui-form {
        margin: 15px 0;
    }
    .layui-form-label {
        width: 100px;
        text-align: left;
    }
    .layui-tab {
        border: 1px solid #00F7DE;
    }
    .tab-ul {
        width: 100%;
    }
    .tab-ul li dd {
        /*width: 13.28%;*/
        height: 60px;
        float: left;
        flex: 1;
        /*border: 1px solid #007DDB;*/
    ;
    }
    .tab-ul-title {
        height: 30px;
        /*width: 50%;*/
        text-align: center;
        line-height: 30px;
        font-size: 16px;
        font-weight: bold;
        /*border: 1px solid #007DDB;*/
        border-bottom: 0
    }
    .week-title td {
        text-align: center;
    }
    .layui-table td {
        padding: 0px!important;
    }
    input[type='text'] {
        /*width: 80px;*/
        margin: 5px auto;
    }
    .ri,
    .ri-w {
        padding: 14px 25px;
        background: #eee;
        text-align: center;
    }
    .batch {
        float: right;
        margin-left: 10px;
    }
    .emptys {
        color: #00F7DE;
    }
    #setPriceShade,#setNewPriceShade {
        /*width: 100%;
        height: 100%;*/
        display: none;
    }
    .bj {
        background: #ff7d00 !important;
        color:#fff !important;
    }
    .tas {
        overflow: hidden
    }

    .layui-table tbody tr:hover {
        background-color: ' ' !important;
    }
    .titl{
        padding: 5px 15px;
        width: 100%;
        text-align: center;
        font-size: 16px;
    }
    .light_star{
        background:#fff;
    }
    .new_star{
        background:greenyellow;
    }
    /*.light_star:after{*/
    /*content:'*';*/
    /*width: 0;*/
    /*height: 0;*/
    /*color: red;*/
    /*margin-left: 4px;*/
    /*}*/
    .new_star:after{
        content:'*';
        width: 0;
        height: 0;
        color: deepskyblue;

    }
    .tabto{
        margin-top: 30px;
    }
    .tabto td{
        background: #eee;
    }
    .tabto input{
        border: none;
        background: #eee;
    }
    #specsPriceSnap table tr td input{
        border: none;
    }
    .person_price_input{
        background: #fff !important;
    }
    .personlog{
        height: auto;
        text-align: left;
    }
    .delPersonlog{
        margin-left: 8px;
        margin-right: 16px;
        color:red
    }
    .day_price,.day_price_no{
        text-align: center;
        color: #ff7d00;
        height: 30px;
        line-height: 30px;
        background: #fff;
    }
    .day_price_no{
        background: #eee;
    }
    .specBatchBtn{
        position: absolute;
        right: 60px;
        top: 54px;
    }
    #setNewPriceShade li{
        width:100%;
        float: left;
    }
    .boldsp{
        font-weight: bold;
    }
    .redsp{
        color:red;
    }
    #specs_table{
        border: groove;
    }
</style>

<body>
<div class="layui-container" style="width:100%;">
    <form class="layui-form" action="">
        <input type="hidden" name="product_id" id="product_id" value="{$product.id}" />
        <ul>
            <li>
                <div class="layui-form-item" style="margin: 0;">
                    <label class="layui-form-label" style="margin:5px 0">产品售卖时间:</label>
                    <div class="layui-input-inline layui-col-md5">
                        <input type="text" id="starttime" name="starttime" value="{$starttime}" placeholder="开始时间" class="layui-input" readonly />
                    </div>
                    <div style=" text-align: center;line-height: 38px;width: 25px;height: 38px;float: left;margin:5px 10px 5px 0;">至</div>
                    <div class="layui-input-inline layui-col-md6">
                        <input type="text" id="endtime" name="endtime" value="{$endtime}" placeholder="结束时间" class="layui-input" readonly/>
                    </div>
                    <div class="layui-input-inline layui-col-md6" style="width:30%;margin-top:4px">
                        <input type="button" style="margin: 5px auto;" value="刷新" onClick="window.location.reload();" class="layui-btn layui-btn-sm" />
                        <input type="button" style="margin: 5px auto;" value="返回上一页" onClick="javascript:history.back(-1);" class="layui-btn layui-btn-sm" />
                    </div>
                </div>
            </li>
            <li>
                <div class="layui-tab" lay-filter="package" style="margin:0">
                    <div id="tab-title">
                        <ul class="layui-tab-title Spec">

                        </ul>
                    </div>
                    <div class="layui-tab-content content" style="overflow: auto;">

                    </div>
                </div>
            </li>
        </ul>
    </form>

    <!--普通成本弹层-->
    <div id="setPriceShade">
        <form class="layui-form" action="" method="post" name="setPriceShade">
            <input type="hidden" id="specs_ids" value="" />
            <ul>
                <li>
                    <div class="layui-form-item" style="margin: 0;">
                        <label class="layui-form-label">售卖日期:</label>
                        <div class="layui-input-inline layui-col-md5">
                            <input type="text" value="{$starttime}" disabled placeholder="开始时间" class="layui-input" readonly />
                        </div>
                        <div style=" text-align: center;line-height: 38px;width: 25px;height: 38px;float: left;margin:5px 10px 5px 0;">至</div>
                        <div class="layui-input-inline layui-col-md6">
                            <input type="text" value="{$endtime}" disabled placeholder="结束时间" class="layui-input" readonly />
                        </div>
                    </div>
                </li>
                <li class="time-content">
                    <div class="layui-form-item shijian" style="margin: 0;">
                        <label class="layui-form-label">选择时间段:<br><span style="font-size: 12px;">(时间为当地时间)</span></label>
                        <div class="layui-input-inline layui-col-md5">
                            <input type="text" name="t-starttime" value="" autocomplete='off' placeholder="开始时间" class="layui-input x" />
                        </div>
                        <div style="text-align: center;line-height: 38px;width: 25px;height: 38px;float: left;margin-right: 10px;">至</div>
                        <div class="layui-input-inline layui-col-md6">
                            <input type="text" name="t-endtime" value="" autocomplete='off' placeholder="结束时间" class="layui-input x" />
                        </div>
                    </div>
                </li>
                <li>
                    <div class="layui-form-item" style="margin: 0;">
                        <label class="layui-form-label">&nbsp;</label>
                        <div class="layui-input-inline layui-col-md12">
                            在以上时间段中选择：
                        </div>
                    </div>
                </li>
                <li>
                    <div class="layui-form-item " id="selectTimeForm">


                    </div>
                    <div class="layui-form-item " id="moreTimeForm" style="display: none;">
                        <label class="layui-form-label">&nbsp;</label>
                        <div class="layui-input-block layui-col-xs8" style="margin: 0;">
                            <input style="width:160px;" type="text" name="moreTime" autocomplete='off' value="" placeholder="开始时间" class="layui-input layui-input-inline x" />
                            <a class="layui-btn layui-btn-sm layui-btn-normal addMoreTime" style="margin-top:8px;">添加</a>
                        </div>
                        <div class="layui-input-block layui-col-xs8" style="margin-left:130px;background: #eee;width:620px;">
                            <div style="width:620px;min-height:50px;" id="moreTimeArr">
                            </div>
                        </div>
                    </div>
                </li>
                <li id="specsPriceSnap">
                    <div class="layui-input-block layui-col-xs10" style="margin-left:130px;width: 800px;">
                        <table class="layui-table">
                            <thead>
                            <tr>
                                <th>名称</th>
                                <th>价格</th>
                                <th>数量</th>
                                <th>最低下单数</th>
                                <th>最小增长数</th>
                            </tr>
                            </thead>
                            <tbody class="batch_person">

                            </tbody>
                        </table>
                    </div>
                </li>
            </ul>
        </form>
    </div>

    <!--包车成本弹层-->
    <div id="setNewPriceShade">
        <form class="layui-form" action="" method="post" name="setNewPriceShade">
            <input type="hidden" id="USD_rate" value="" />
            <input type="hidden" id="CAD_rate" value="" />
            <input type="hidden" id="JPY_rate" value="" />
            <input type="hidden" id="vehicle_rate" value="" />
            <input type="hidden" id="hotel_rate" value="" />
            <input type="hidden" id="ticket_rate" value="" />
            <input type="hidden" id="new_specs_ids" value="" />
            <ul>
                <li>
                    <div class="layui-form-item" style="margin: 0;">
                        <label class="layui-form-label">售卖日期:</label>
                        <div class="layui-input-inline layui-col-md5">
                            <input type="text" value="{$starttime}" disabled placeholder="开始时间" class="layui-input" readonly />
                        </div>
                        <div style=" text-align: center;line-height: 38px;width: 25px;height: 38px;float: left;margin:5px 10px 5px 0;">至</div>
                        <div class="layui-input-inline layui-col-md6">
                            <input type="text" value="{$endtime}" disabled placeholder="结束时间" class="layui-input" readonly />
                        </div>
                    </div>
                </li>
                <li class="time-content">
                    <div class="layui-form-item shijian" style="margin: 0;">
                        <label class="layui-form-label">选择时间段:<br><span style="font-size: 12px;">(时间为当地时间)</span></label>
                        <div class="layui-input-inline layui-col-md5">
                            <input type="text" name="nt-starttime" autocomplete="off" value="" placeholder="开始时间" class="layui-input x" />
                        </div>
                        <div style="text-align: center;line-height: 38px;width: 25px;height: 38px;float: left;margin-right: 10px;">至</div>
                        <div class="layui-input-inline layui-col-md6">
                            <input type="text" name="nt-endtime" autocomplete="off" value="" placeholder="结束时间" class="layui-input x" />
                        </div>
                    </div>
                </li>
                <li>
                    <div class="layui-form-item" style="margin: 0;">
                        <label class="layui-form-label">&nbsp;</label>
                        <div class="layui-input-inline layui-col-md12">
                            在以上时间段中选择：
                        </div>
                    </div>
                </li>
                <li>
                    <div class="layui-form-item" id="selectNewTimeForm">

                    </div>
                </li>
                <li>
                    <label class="layui-form-label" style="width:130px;">套餐规格:</label>
                    <div class="layui-input-inline layui-col-xs10">
                        <table class="layui-table" id="specs_table" lay-size="sm">
                            <thead id="specs_head">
                            <tr>
                                <th>车型</th>
                                <th>成本</th>
                                <th>利率</th>
                                <th>售卖价格</th>
                            </tr>
                            </thead>
                            <tbody id="specs_body">

                            </tbody>
                        </table>
                    </div>
                </li>
                <li>
                    <label class="layui-form-label" style="width:130px;">用车成本（按车）:</label>
                    <div class="layui-input-inline layui-col-xs10">
                        <table class="layui-table" lay-size="sm">
                            <thead>
                            <tr>
                                <th>车型</th>
                                <th>成本（{$currencyName}{$currency}）</th>
                                <th>
                                    <input type="hidden" id="exchangeNum" value="{$exchangeNum}">
                                    实时汇率
                                </th>
                                <th>成本（人民币￥）</th>
                            </tr>
                            </thead>
                            <tbody>
                            <tr>
                                <th>5座车</th>
                                <th>
                                    <div style="width:5%;float: left;line-height: 40px;color:red;">{$currency}</div>
                                    <div style="width:92%;float: left;">
                                        <input type="number" id="5_cost_currency" class="layui-input" placeholder="请填写{$currencyName}成本" value="{$carPriceArr.f_cost}" />
                                    </div>
                                </th>
                                <th>{$exchangeNum}</th>
                                <th>
                                    <div style="width:5%;float: left;line-height: 40px;color:red;">￥</div>
                                    <div style="width:92%;float: left;">
                                        <input type="number" id="5_cost" readonly class="layui-input" placeholder="请填写成本" value="" />
                                    </div>
                                </th>
                            </tr>
                            <tr>
                                <th>7座车</th>
                                <th>
                                    <div style="width:5%;float: left;line-height: 40px;color:red;">{$currency}</div>
                                    <div style="width:92%;float: left;">
                                        <input type="number" id="7_cost_currency" class="layui-input" placeholder="请填写{$currencyName}成本" value="{$carPriceArr.s_cost}" />
                                    </div>
                                </th>
                                <th>{$exchangeNum}</th>
                                <th>
                                    <div style="width:5%;float: left;line-height: 40px;color:red;">￥</div>
                                    <div style="width:92%;float: left;">
                                        <input type="number" id="7_cost" readonly class="layui-input" placeholder="请填写成本" value="" />
                                    </div>
                                </th>
                            </tr>
                            <tr>
                                <th>12座车</th>
                                <th>
                                    <div style="width:5%;float: left;line-height: 40px;color:red;">{$currency}</div>
                                    <div style="width:92%;float: left;">
                                        <input type="number" id="12_cost_currency" class="layui-input" placeholder="请填写{$currencyName}成本" value="{$carPriceArr.t_cost}" />
                                    </div>
                                </th>
                                <th>{$exchangeNum}</th>
                                <th>
                                    <div style="width:5%;float: left;line-height: 40px;color:red;">￥</div>
                                    <div style="width:92%;float: left;">
                                        <input type="number" id="12_cost" readonly class="layui-input" placeholder="请填写成本" value="" />
                                    </div>
                                </th>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                </li>
                <li class="more_cost_li" style="display: none;">
                    <label class="layui-form-label" style="width:130px;">酒店成本（每间）:</label>
                    <div class="layui-input-inline layui-col-xs10">
                        <table class="layui-table" lay-size="sm">
                            <thead>
                            <tr>
                                <th>城市</th>
                                <th>星级</th>
                                <th>几晚</th>
                                <th>成本价格(每间/每晚)</th>
                            </tr>
                            </thead>
                            <tbody id="hotel_body">

                            </tbody>
                        </table>
                    </div>
                </li>
                <li class="more_cost_li" style="display: none;">
                    <label class="layui-form-label" style="width:130px;">门票成本（每人）:</label>
                    <div class="layui-input-inline layui-col-xs10">
                        <table class="layui-table" lay-size="sm">
                            <thead>
                            <tr>
                                <th>门票名称</th>
                                <th>张数</th>
                                <th>成本价格</th>
                            </tr>
                            </thead>
                            <tbody id="ticket_body">

                            </tbody>
                        </table>
                    </div>
                </li>
                <li>
                    <label class="layui-form-label" style="width:130px;">酒店门票成本启用:</label>
                    <div class="layui-input-inline" style="margin-top:10px;">
                        <button data-id="0" id="more_btn" class="layui-btn layui-btn-danger">未启用</button>
                    </div>
                </li>
            </ul>
        </form>
    </div>

</div>
</body>
<script src="__PUBLIC__/layui/layui.js"></script>
<script src="__PUBLIC__/jquery/jquery.min.js"></script>
<script type="text/javascript">
    var moreTimeList = [];
    layui.use(['layer', 'element', 'form', 'laydate'], function() {
        //套餐获取
        var specsurl = '/admin/product/werk';
        //规格获取
        var posurl = '/admin/product/pos';
        //获取数据
        var starttime = "{$starttime}";
        var endtime = "{$endtime}";
        var personprice = {};
        var id = {$product.id};
        var list = {$data};
        var layer = layui.layer,
            element = layui.element,
            form = layui.form,
            laydate = layui.laydate;

        //重新渲染所有的日期控件
        function renderDateTimeWidget(){
            //重新渲染时间控件
            $('.x').each(function() {
                laydate.render({
                    elem: this //指定元素
                    ,trigger:'click'
                });
            });
        }
        renderDateTimeWidget();

        //获取产品全部日期价格集合
        function getPersonPrice(){
            $.ajax({
                url:"/admin/product/getPrice",
                type:"POST",
                dataType:'json',
                async:false,
                data:{id:id,sdate:starttime,edate:endtime},
                success:function (data) {
                    personprice = data.data;
                }
            })
        }
        getPersonPrice();

        //初始化
        //1-1   获取并渲染产品套餐
        function showSpecsData(){
            $('.Spec').html(''); //清空容器
            var id = $('#product_id').val(); //获取产品id
            var starttime = $('#starttime').val(); //获取开始时间
            var endtime = $('#endtime').val(); //获取结束时间
            if(starttime.length <= 0) {
                layer.msg('开始时间不能为空');
                return false;
            }
            if(endtime.length <= 0) {
                layer.msg('结束时间不能为空');
                return false;
            }

            //开始时间转化时间戳
            var k = parseInt(new Date(starttime + ' 00:00:00').getTime());
            //结束时间转化时间戳
            var j = parseInt(new Date(endtime + ' 23:59:59').getTime());
            //获取当前时间戳
            var d = parseInt(new Date().getTime());
            if(j < k) {
                layer.msg('结束时间不能小于开始时间');
                return false;
            }

            //获取套餐
            $.ajax({
                url: specsurl,
                type: "post",
                dataType: "json",
                data: {
                    id: id
                },
                success: function(resData) {
                    if(resData.code==-1){
                        layer.msg("请先添加套餐");
                        return false;
                    }
                    resData = resData.data;
                    var packageHtml = ''; //套餐表头html
                    var priceHtml = ''; //价格内容html
                    $('.content').html('');
                    $.each(resData, function(i, v) {
                        var thisHtml = '';
                        var thisShowHtml = '';
                        if(i==0) {
                            thisHtml = 'class="layui-this"';
                            thisShowHtml = 'layui-show';
                        }else{
                            thisHtml = '';
                            thisShowHtml = '';
                        }
                        var package_id = v.id;
                        var normalSet = '<div date-pid="' + package_id + '" class="batch addBatch layui-btn layui-btn-sm layui-btn-normal">普通成本</div>';
                        packageHtml += '<li id="top' + package_id + '"' + thisHtml + 'data-id="' + package_id + '">' + v.name + '</li>';
                        priceHtml += '<div class="layui-tab-item '+ thisShowHtml +'" id="yue' + package_id + '">' +
                            '<ul class="tab-ul">' +
                            '<li class="tab-ul-title specBatchBtn">' +
                            '<div date-pid="' + package_id + '" class="batch deleteBatch layui-btn layui-btn-sm layui-btn-danger">批量删除</div>' +
                            normalSet +
                            '<div date-pid="' + package_id + '" class="batch addNewBatch layui-btn layui-btn-sm layui-btn-default">包车成本</div>' +
                            '<div date-pid="' + package_id + '" class="batch setGoodsRate layui-btn layui-btn-sm layui-btn-warm">成本系数</div>' +
                            '</li>' +
                            '</ul>' +
                            '<div class="layui-tab yue_div">' +
                            '<ul class="layui-tab-title" id="yue">' +
                            '</ul>' +
                            '<div class="layui-tab-content tas" id="tas' + package_id + '">' +
                            '</div>' +
                            '</div>' +
                            '<div class="layui-form-item ">' +
                            '</div>' +
                            '</div>' +
                            '</div>';
                        $('.Spec').html(packageHtml);
                        $('.content').html(priceHtml);
                    });
                    addhtm(starttime,endtime,resData);
                },
                error: function(jqXHR) {
                    console.log(jqXHR);
                }
            });
        }
        $(document).ready(function(){
            showSpecsData();
        });

        //2-1       渲染价格日历、规格
        function addhtm(starttime,endtime,resData) {
            var package_id = resData[0].id;
            $.ajax({
                url: posurl,
                type: "post",
                dataType: "json",
                data: {
                    'package_id': package_id
                },
                success: function(data) {
                    yue(starttime, endtime, package_id, data);
                },
                error: function(jqXHR) {
                    console.log(jqXHR);
                }
            });
        }
        //2-2       获取区间内的月份
        function yue(starttime, endtime, package_id, data) {
            var da = getMonthAll(starttime, endtime);
            var month = '';
            $('#tas' + package_id).html('');
            for(var i = 0; i < da.length; i++) {
                var year = da[i].split('-');
                if(i == 0) {
                    month += '<li class="layui-this" lay-id="' + i + '">' + year[0] + '年' + year[1] + '月</li>';
                } else {
                    month += '<li  lay-id="' + i + '">' + year[0] + '年' + year[1] + '月</li>';
                }
                var tasHtml = datetime(da[i], i, data, package_id, starttime, endtime);
                $('#tas' + package_id).append(tasHtml);
                //高亮第一个时间
                $(".ri:first").click();
            }
            $('#yue' + package_id + ' #yue').html('');
            $('#yue' + package_id + ' #yue').prepend(month);
        }
        //2-2-1     查询时间维度里的所有月份
        function getMonthAll(starttime, endtime) {
            var d1 = starttime;
            var d2 = endtime;
            var dateArry = new Array();
            var s1 = d1.split("-");
            var s2 = d2.split("-");
            var mCount = 0;
            if(parseInt(s1[0]) < parseInt(s2[0])) {
                mCount = (parseInt(s2[0]) - parseInt(s1[0])) * 12 + parseInt(s2[1]) - parseInt(s1[1]) + 1;
            } else {
                mCount = parseInt(s2[1]) - parseInt(s1[1]) + 1;
            }
            if(mCount > 0) {
                var startM = parseInt(s1[1]);
                var startY = parseInt(s1[0]);
                for(var i = 0; i < mCount; i++) {
                    if(startM < 12) {
                        dateArry[i] = startY + "-" + (startM > 9 ? startM : "0" + startM);
                        startM += 1;
                    } else {
                        dateArry[i] = startY + "-" + (startM > 9 ? startM : "0" + startM);
                        startM = 1;
                        startY += 1;
                    }
                }
            }
            return dateArry;
        }
        //2-2-2     渲染日历
        function datetime(up, d, data, package_id, starttime, endtime) {
            starttime = starttime.split("-");
            endtime = endtime.split("-");
            up = up.split("-");
            var da = new Date(up[0], up[1], 0);
            //获取每月有多少天
            var day = da.getDate(); //获取当前月有多少天
            da.setDate(1);
            var we = da.getDay(); //获取当前月的第一天是星期几
            var a = 0;
            var str = '';
            var tr = '';
            var tab = ''; ///每一天的tab
            if(d == 0) {
                tr += '<div class="layui-tab-item layui-show">';
            } else {
                tr += '<div class="layui-tab-item">';
            }
            tr += "<div class='layui-col-md6'>";
            tr += '<table class="layui-table">' +
                '<div class="titl">' + up[0] + '年' + up[1] +'月</div>'+
                '<thead>' +
                '<tr class="week-title">' +
                '<td>星期日</td>' +
                '<td>星期一</td>' +
                '<td>星期二</td>' +
                '<td>星期三</td>' +
                '<td>星期四</td>' +
                '<td>星期五</td>' +
                '<td>星期六</td>' +
                '</tr>' +
                '</thead>' +
                '<tbody class="tian">';

            for(var i = 1; i <= day + we; i++) {
                a++;
                if(i > we) {
                    //按时间段渲染日历
                    var light = '';
                    var firstPrice = '';
                    var day_price_str = "";
                    var u = i - we;
                    var str_class = up[0] + '-' + up[1] + '-' + (u > 9 ? u : '0' + u) + '">' + (u > 9 ? u : '0' + u);
                    var str_day = up[0] + '-' + up[1] + '-' + (u > 9 ? u : '0' + u);
                    if(str_day+','+package_id in personprice){
                        light = 'light_star show';
                        var day_index = str_day+','+package_id;
                        firstPrice = personprice[day_index][0]['price'] || "";
                    }
                    if(firstPrice!=""){
                        day_price_str = '<div class="day_price"><p style="width:80%;margin:0 auto;border-top:1px solid #ddd">¥'+firstPrice+'</p></div>';
                    }else{
                        day_price_str = '<div class="day_price_no"></div>';
                    }
                    if(u < starttime[2] && up[0] == starttime[0] && up[1] == starttime[1] || u > endtime[2] && up[0] == endtime[0] && up[1] == endtime[1]) {
                        str += '<td>' +
                            '<div class="ri-w '+light+'" date-specs="' + package_id + '" date-ri="' + str_class +'</div>' + day_price_str +
                            '</td>';
                    } else {
                        str += '<td>' +
                            '<div class="ri '+light+'" date-specs="' + package_id + '" date-ri="' + str_class +'</div>' + day_price_str +
                            '</td>';
                    }
                } else {
                    str += '<td></td>';
                }
                if(a == 7 || i == day + we) {
                    tr += '<tr>' + str + '</tr>';
                    str = '';
                    a = 0;
                }
                if(u === undefined) {

                } else {
                    if(u < starttime[2] && up[0] == starttime[0] && up[1] == starttime[1] || u > endtime[2] && up[0] == endtime[0] && up[1] == endtime[1]) {

                    } else {
                        var time = up[0] + '-' + up[1] + '-' + (u > 9 ? u : '0' + u);
                        tab += '<div class="person_off " id="' + up[0] + '-' + up[1] + '-' + (u > 9 ? u : '0' + u) + '" style="display: none;">' +
                            '<table class="layui-table">';
                        tab += '<thead><tr><th>名称</th><th>价格</th><th>数量</th><th>最低下单</th><th>最小增长</th></tr></thead>';
                        tab += '<tbody>';

                        //循环人群
                        //默认使用套餐数据填充 改用真实数据填充 2019-03-19
                        var oldperson = list[time+","+package_id];
                        if(oldperson!==undefined && oldperson!==null){
                            data = oldperson;
                        }else if(time+','+package_id in personprice){
                            data = personprice[time+","+package_id];
                        }
                        for(var j = 0; j < data.length; j++) {
                            var dayTitle = up[0] + '-' + up[1] + '-' + (u > 9 ? u : '0' + u);
                            tab += '<tr date-trd="' + dayTitle + '" date-person="' + data[j].person_id + '" >' +
                                '<td><input readonly type="text" name="person_name" date-aid="' + data[j].id + '" date-rq="' + dayTitle + '" class="layui-input" placeholder="名称" value="' + data[j].name + '" /></td>' +
                                '<td><input type="number" name="person_price" date-dayid="' + data[j].id + '" date-rq="' + dayTitle + '" class="layui-input person_price_input" placeholder="价格" value="' + data[j].price + '" /></td>' +
                                '<td><input readonly type="number" name="person_num" date-aid="' + data[j].id + '" date-rq="' + dayTitle + '"  class="layui-input" placeholder="数量" value="' + data[j].num + '" />' +
                                '</td>' +
                                '<td><input readonly type="number" name="minorder_num" date-aid="' + data[j].id + '" date-rq="' + dayTitle + '"  class="layui-input" placeholder="最低下单数" value="' + data[j].minorder_num + '" /></td>' +
                                '<td><input readonly type="number" name="inc_order_num" date-aid="' + data[j].id + '" date-rq="' + dayTitle + '"  class="layui-input" placeholder="最小增长数" value="' + data[j].inc_order_num + '" /></td>';
                            tab += '</tr>';
                        }
                        tab +=
                            '</tbody>' +
                            '</table>' +'<a class="layui-btn layui-btn-sm layui-btn-normal modifySingleDayPrice">保存</a>' +
                            '</div>';
                    }
                }
            }

            tr += '</tbody>' +
                '</table>' +
                '</div>' +
                '<div class="layui-col-md1">&nbsp</div>' +
                '<div class="layui-col-md5 tabto">' + tab + '</div>' +
                '</div>';
            return tr;
        }

        //日历点击展示当日规格&价格
        function clickOneday(_that,type){
            $('.ri').removeClass('bj');
            $('.day_price').removeClass('bj');
            _that.addClass('bj');
            var ri;
            var specs;
            if(type=='date'){
                ri = _that.attr('date-ri');
                specs = _that.attr('date-specs');
                _that.next().addClass('bj')
            }else{
                ri = _that.prev().attr('date-ri');
                specs = _that.prev().attr('date-specs');
                _that.prev().addClass('bj')
            }
            $('#yue' + specs + ' #' + ri).siblings().hide();
            $('#yue' + specs + ' #' + ri).show();
            //点击时间弹框 取消自20190319-bywtt
            layer.msg(ri + '号', {
                time: 700
            });
        }
        $(document).on('click', '.ri', function() {
            if($(this).hasClass('show')){
                clickOneday($(this),'date')
            }
        });
        $(document).on('click', '.day_price', function() {
            if($(this).prev().hasClass('show')){
                clickOneday($(this),'price')
            }
        });

        //切换套餐
        element.on('tab(package)', function() {
            var starttime = $('#starttime').val(); //获取开始时间
            var endtime = $('#endtime').val(); //获取结束时间
            var package_id = this.getAttribute('data-id'); //获取套餐id
            if($('#yue' + package_id + ' #yue').is(":empty")) {
                $.ajax({
                    url: posurl,
                    type: "post",
                    dataType: "json",
                    data: {'package_id': package_id},
                    success: function(data) {
                        yue(starttime, endtime, package_id, data);
                    },
                    error: function(jqXHR) {
                        console.log(jqXHR);
                    }
                });
            }
        });

        /*********【普通成本】配置弹窗   click打开*************/
        //【普通成本】
        $(document).on('click', '.addBatch', function() {
            //添加时需要展示快照信息
            $("#specsPriceSnap").show();
            var package_id = $(this).attr('date-pid');
            $.post(posurl, {
                'package_id': package_id
            }, function(data) {
                renderSelectTimeForm();
                form.render();
                renderPersonList(data);
            });
            //显示添加时间的按钮 不允许修改
            $(".addMoreTime").show();
            moreTimeList = [];
            $("#moreTimeArr").children().remove();
            //打开一个弹窗 点击保存触发事件
            layer.open({
                type: 1,
                area: ['95%', '95%'],
                btn: ['保存', '取消'],
                content: $('#setPriceShade'),
                yes: function(index, layero) {
                    var pro_start_day = $('#starttime').val(); //获取开始时间
                    var pro_end_day = $('#endtime').val(); //获取结束时间
                    var save_start_day = $("input[name=t-starttime]").val();
                    var save_end_day = $("input[name=t-endtime]").val();
                    var pro_start_time = parseInt(new Date(pro_start_day + ' 00:00:00').getTime());
                    var save_start_time = parseInt(new Date(save_start_day + ' 00:00:00').getTime());
                    var pro_end_time = parseInt(new Date(pro_end_day + ' 23:59:59').getTime());
                    var save_end_time = parseInt(new Date(save_end_day + ' 23:59:59').getTime());
                    if(save_start_time < pro_start_time) {
                        layer.msg('时间段开始时间小于产品上架时间');
                        return false;
                    }
                    if(save_end_time > pro_end_time) {
                        layer.msg('时间段结束时间大于产品下架时间');
                        return false;
                    }
                    if(save_end_time < save_start_time) {
                        layer.msg('结束时间不能小于开始时间');
                        return false;
                    }
                    var time_type = $('input[name=time_type]:checked').val();
                    var month_value = $('input[name=month_value]:checked').val();
                    var time_value = [];
                    if(time_type==0 || time_type==3){
                        time_value = '';
                    }else if(time_type==1){
                        time_value = month_value;
                    }else{
                        var week_value = $("input[name=week]:checked");
                        if(week_value.length<1){
                            layer.msg("请选择日期类型");
                            return false;
                        }else{
                            $.each(week_value,function(i,v){
                                time_value.push($(v).val())
                            });
                            time_value = time_value.join(",");
                        }
                    }
                    //获取筛选的数据
                    var selectDays = getDaysByDates(save_start_day,save_end_day,time_type,time_value);
                    if(time_type==3){
                        selectDays = moreTimeList;
                    }
                    if(selectDays.length < 1){
                        layer.msg("您选择的时间段中没有时间被选择");
                        return false;
                    }
                    //保存数据
                    savePackageData(package_id,selectDays,moreTimeList);
                }
            });
        });
        //【批量删除】
        $(document).on('click', '.deleteBatch', function() {
            //删除时不需要展示快照信息
            $("#specsPriceSnap").hide();
            var package_id = $(this).attr('date-pid');
            $.post(posurl, {'package_id': package_id}, function(da) {
                renderSelectTimeForm();
                form.render();
                renderPersonList(da);
            });
            //显示添加时间的按钮 允许修改
            $(".addMoreTime").show();
            moreTimeList = [];
            $("#moreTimeArr").children().remove()
            //打开一个弹窗 点击保存触发事件
            layer.open({
                type: 1,
                area: ['1000px', '70%'],
                btn: ['删除', '取消'],
                content: $('#setPriceShade'),
                yes: function(index, layero) {
                    var pro_start_day = $('#starttime').val(); //获取开始时间
                    var pro_end_day = $('#endtime').val(); //获取结束时间
                    var save_start_day = $("input[name=t-starttime]").val();
                    var save_end_day = $("input[name=t-endtime]").val();
                    var pro_start_time = parseInt(new Date(pro_start_day + ' 00:00:00').getTime());
                    var save_start_time = parseInt(new Date(save_start_day + ' 00:00:00').getTime());
                    var pro_end_time = parseInt(new Date(pro_end_day + ' 23:59:59').getTime());
                    var save_end_time = parseInt(new Date(save_end_day + ' 23:59:59').getTime());
                    if(save_start_time < pro_start_time) {
                        layer.msg('时间段开始时间小于产品上架时间');
                        return false;
                    }
                    if(save_end_time > pro_end_time) {
                        layer.msg('时间段结束时间大于产品下架时间');
                        return false;
                    }
                    if(save_end_time < save_start_time) {
                        layer.msg('结束时间不能小于开始时间');
                        return false;
                    }
                    var time_type = $('input[name=time_type]:checked').val();
                    var month_value = $('input[name=month_value]:checked').val();
                    var time_value = [];
                    if(time_type==0 || time_type==3){
                        time_value = '';
                    }else if(time_type==1){
                        time_value = month_value;
                    }else{
                        var week_value = $("input[name=week]:checked");
                        if(week_value.length<1){
                            layer.msg("请选择日期类型");
                            return false;
                        }else{
                            $.each(week_value,function(i,v){
                                time_value.push($(v).val())
                            });
                            time_value = time_value.join(",");
                        }
                    }
                    //获取筛选的数据
                    var selectDays = getDaysByDates(save_start_day,save_end_day,time_type,time_value);
                    if(time_type==3){
                        selectDays = moreTimeList;
                    }
                    if(selectDays.length < 1){
                        layer.msg("您选择的时间段中没有时间被选择");
                        return false;
                    }
                    // 保存数据
                    packageDeleteData(package_id,selectDays,moreTimeList);
                }
            });
        });
        //修改单日的套餐价格
        $(document).on('click','.modifySingleDayPrice',function(){
            var priceTable = $(this).prev().find('.person_price_input');
            var postdata = [];
            var flag = true;
            $.each(priceTable,function(i,v){
                var id = $(v).attr('date-dayid');
                var price = $(v).val();
                if(price=="" || price<=0 || price==undefined){
                    flag = false;
                    return false;
                }else{
                    postdata.push({id:id,price:price});
                }
            });
            if(!flag){
                layer.msg("请填写所有的价格！");return false;
            }else{
                postdata = JSON.stringify(postdata);
                var product_id = $('#product_id').val(); //获取产品id
                $.post("/admin/product/setSingleDayPrice",{product_id:product_id,data:postdata},function(data){
                    layer.msg(data.msg);
                    if(data.code=='200'){
                        setTimeout(function(){
                            window.location.reload();
                        },1000)
                    }
                },'json')
            }
        });

        //【普通成本】弹窗中时间段选择渲染
        function renderSelectTimeForm(){
            $('#selectTimeForm').children().remove();
            var str = '<label class="layui-form-label">&nbsp;</label>\n' +
                '                        <div class="layui-input-block layui-col-xs6" style="margin: 0;">\n' +
                '                            <input type="radio" lay-filter="time_type" title="全部" checked name="time_type" value="0" />\n' +
                '                            <input type="radio" lay-filter="time_type" title="按单双日" name="time_type" value="1" />\n' +
                '                            <input type="radio" lay-filter="time_type" title="按星期" name="time_type" value="2" />\n' +
                '                        </div>\n' +
                '                        <div class="layui-input-block layui-col-xs8" id="single" style="margin: 0;display: none;">\n' +
                '                            <input type="radio" lay-filter="month_value" title="每月单日" name="month_value" value="8" />\n' +
                '                            <input type="radio" lay-filter="month_value" title="每月双日" name="month_value" value="9" />\n' +
                '                        </div>\n' +
                '                        <div class="layui-input-block layui-col-xs8" id="week" style="margin: 0;display: none;">\n' +
                '                            <input type="checkbox" lay-skin="primary" lay-filter="xq" title="每周一" class="time_week" name="week" value="1" />\n' +
                '                            <input type="checkbox" lay-skin="primary" lay-filter="xq" title="每周二" class="time_week" name="week" value="2" />\n' +
                '                            <input type="checkbox" lay-skin="primary" lay-filter="xq" title="每周三" class="time_week" name="week" value="3" />\n' +
                '                            <input type="checkbox" lay-skin="primary" lay-filter="xq" title="每周四" class="time_week" name="week" value="4" />\n' +
                '                            <input type="checkbox" lay-skin="primary" lay-filter="xq" title="每周五" class="time_week" name="week" value="5" />\n' +
                '                            <input type="checkbox" lay-skin="primary" lay-filter="xq" title="每周六" class="time_week" name="week" value="6" />\n' +
                '                            <input type="checkbox" lay-skin="primary" lay-filter="xq" title="每周日" class="time_week" name="week" value="0" />\n' +
                '                        </div>\n';
            $('#selectTimeForm').append(str);
        }
        //【普通成本】弹窗中规格table渲染
        function renderPersonList(data){
            //渲染规格
            $('.batch_person').html('');
            var sr = '';
            $.each(data, function(i, v) {
                sr += '<tr date-id="' + v.person_id + '">' +
                    '<td><input readonly type="text" name="person_name" id="person_name" class="layui-input" placeholder="' + v.name + '" value="' + v.name + '"/>' +
                    '<input type="hidden" name="person_id" id="person_id" class="layui-input" value="' + v.id + '"/></td>' +
                    '<td><input type="text" name="person_price" id="person_price" class="layui-input" placeholder="' + v.name + '成本" value=""/></td>' +
                    '<td><input readonly type="text" name="person_num" id="person_num" class="layui-input" placeholder="库存" value="' + v.num + '" /></td>' +
                    '<td><input readonly type="text" name="minorder_num" id="minorder_num" class="layui-input" placeholder="最低下单数" value="' + v.minorder_num +'" /></td>' +
                    '<td><input readonly type="text" name="inc_order_num" id="inc_order_num" class="layui-input" placeholder="最小增长数" value="' + v.inc_order_num +'" /></td></tr>';
            });

            $('.batch_person').html(sr);
            form.render('select');
        }

        //提交数据时组装日期价格数据
        function getDaysByDates(starttime,endtime,time_type,time_value){
            var dateArry = new Array();
            var s1 = starttime.split("-");
            var s2 = endtime.split("-");
            var monthCount = 0;
            if(parseInt(s1[0]) < parseInt(s2[0])) {
                monthCount = (parseInt(s2[0]) - parseInt(s1[0])) * 12 + parseInt(s2[1]) - parseInt(s1[1]) + 1;
            } else {
                monthCount = parseInt(s2[1]) - parseInt(s1[1]) + 1;
            }
            var stime= new Date(starttime+' 00:00:00').getTime()-1000;
            var etime= new Date(endtime+' 23:59:59').getTime();
            if(monthCount > 0) {
                var startM = parseInt(s1[1]);
                var startY = parseInt(s1[0]);
                for(var i = 0; i < monthCount; i++) {
                    var da = new Date(startY, startM, 0);
                    //获取每月有多少天
                    var day = da.getDate(); //获取当前月有多少天
                    for(j = 1; j <= day; j++) {
                        var the_day = startY + "-" + (startM > 9 ? startM : "0" + startM) + "-" + (j > 9 ? j : "0" + j);
                        var curtime = new Date(startY + '-' + startM + '-' + j + ' 00:00:00');
                        var curtime = curtime.getTime();
                        if(curtime < stime || curtime > etime){
                            continue;
                        }
                        if (time_type == 0) {
                            dateArry.push(the_day);
                        } else if(time_type ==1) {
                            //单日
                            if (j % 2 == 1 && time_value == '8') {
                                dateArry.push(the_day);
                            } else if (j % 2 == 0 && time_value == '9') {
                                //双日
                                dateArry.push(the_day);
                            }
                        }else if(time_type ==2){
                            //周
                            var value = time_value.split(",");
                            var w = new Date(startY + '-' + startM + '-' + j)
                            var the_week = w.getDay();
                            var index= value.indexOf(String(the_week));
                            if ( index > -1) {
                                dateArry.push(the_day);
                            }

                        }
                    }
                    if(startM<12){
                        startM += 1;
                    }else{
                        startM = 1;
                        startY += 1;
                    }
                }
            }
            return dateArry;
        }
        //【普通成本】提交数据
        function savePackageData(package_id,date,more_time){
            //记录数据
            var postData = {};
            //组装数组
            var specs = [];
            var personlist = $(".batch_person tr");
            $.each(personlist,function(i,v){
                var spec = {};
                spec.id = $(v).find("input[name=person_id]").val();
                spec.price = $(v).find("input[name=person_price]").val();
                specs.push(spec);
            });
            postData.specs = specs;
            postData.date = date;
            //组装时间集合
            postData.package_id = package_id;
            postData.more_time = more_time;
            var param = JSON.stringify(postData);
            var shadowindex = layer.load(1);
            $.post("/admin/product/ajaxsetgoodsprice",{param},function(data){
                layer.close(shadowindex);
                layer.msg(data.msg);
                if(data.code==200){
                    setTimeout(function(){
                        window.location.reload();
                    },1500);
                }
            },'json');
            return true;
        }
        //【批量删除】提交数据
        function packageDeleteData(package_id,date,more_time){
            var postData = {};
            postData.date = date;
            //组装时间集合
            postData.package_id = package_id;
            postData.more_time = more_time;
            var param = JSON.stringify(postData);
            var shadowindex = layer.load(1);
            $.post("/admin/product/delsetgoodsprice",{param},function(data){
                layer.close(shadowindex);
                layer.msg(data.msg);
                if(data.code==200){
                    setTimeout(function(){
                        window.location.reload();
                    },1500)
                }
            },'json');
            return true;
        }

        //点击日期类型 切换tab
        function changeTimeType(value){
            if(value==1){
                $("#single").show();
                $("#week").hide();
                $("#moreTimeForm").show();
            }else if(value==2){
                $("#single").hide();
                $("#week").show();
                $("#moreTimeForm").show();
            }else if(value==3){
                $("#single").hide();
                $("#week").hide();
                $("#moreTimeForm").show();
            }else{
                $("#single").hide();
                $("#week").hide();
                $("#moreTimeForm").hide();
            }
        }
        //弹框日期选择
        form.on('radio(time_type)', function(data) {
            var value = data.value;
            changeTimeType(value);
        });
        //弹层单选按钮
        form.on('radio(radio)', function(data) {
            if(data.value == 3) {
                $('#chx').css('display', 'block');
            } else {
                $('#chx').css('display', 'none');
            }
        });

        //【普通成本】弹窗中时间段
        //添加具体的天数
        $(".addMoreTime").click(function(){
            var currentTime = $("input[name=moreTime]").val();
            var t_starttime=$("input[name=t-starttime]").val();
            var t_endtime=$("input[name=t-endtime]").val();
            if(t_starttime=='' || t_endtime==''){
                layer.msg("请选择开始和结束时间");return false;
            }else if(currentTime=="" || currentTime==undefined){
                layer.msg("请选择时间");
            }else if($.inArray(currentTime,moreTimeList)>-1){
                layer.msg("请勿重复添加时间");
            }else if(currentTime<t_starttime || currentTime > t_endtime){
                layer.msg("请在开始和结束时间之间选择");
            }else{
                moreTimeList.push(currentTime);
                var str = '<a class="layui-btn layui-btn-sm layui-bg-cyan delMoreTime" data-id="'+currentTime+'" style="margin:8px;">'+currentTime+' <i class="layui-icon">&#x1006;</i></a>\n';
                $("#moreTimeArr").append(str);
            }
        });
        //删除具体的天数
        $(document).on('click','.delMoreTime',function(){
            var currentTime = $(this).attr('data-id');
            moreTimeList.splice($.inArray(currentTime,moreTimeList),1);
            $(this).remove();
        });



        /*********【成本系数】配置弹窗   click打开*************/
        //【成本系数】
        $(document).on('click', '.setGoodsRate', function() {
            var product_id = $("#product_id").val();
            var url = "/admin/product/setvehicleinfo?id="+product_id;
            //打开一个弹窗 点击保存触发事件
            layer.open({
                type:2,
                content:url,
                area: ['90%', '90%'],
                end:function(){
                    location.reload();
                }
            });
        });


        /*********【包车成本】配置弹窗   click打开*************/
        //【包车成本】
        $(document).on('click', '.addNewBatch', function(){
            var product_id = $("#product_id").val();
            var package_id = $(this).attr('date-pid');
            //show时间段选择
            renderSelectTimeFormNew();
            form.render();

            //获取酒店门票数据
            $.ajax({
                url:"/admin/product/getPriceSetData",
                type:"POST",
                dataType:'json',
                data:{product_id:product_id},
                success:function (res) {
                    if(res.code==1){
                        var hotel_data = res.data.product.hotel_price_json;
                        var currency = res.data.product.currency;//货币类型
                        var ticket_data = res.data.ticket;
                        var exchange_data = res.data.exchange;

                        $("#vehicle_rate").attr("value",res.data.product.vehicle_rate);
                        $("#hotel_rate").attr("value",res.data.product.hotel_rate);
                        $("#ticket_rate").attr("value",res.data.product.ticket_rate);

                        $.each(exchange_data, function(i, v) {
                            if(v.currency_code=='USD'){
                                $("#USD_rate").attr("value",v.exchange_rate);
                            }else if(v.currency_code=='CAD'){
                                $("#CAD_rate").attr("value",v.exchange_rate);
                            }else if(v.currency_code=='JPY'){
                                $("#JPY_rate").attr("value",v.exchange_rate);
                            }
                        });

                        var hotel_html = '';
                        if(hotel_data!==null){
                            $.each(hotel_data, function(i, v) {
                                hotel_html += '<tr>' +
                                    '<th>'+v.cityName+'</th>' +
                                    '<th>'+v.levelName+'</th>' +
                                    '<th>'+v.days+'晚</th>' +
                                    '<th><div style="width:8%;float: left;line-height: 40px;">'+v.cost.currSymbol+'</div>' +
                                    '<div style="width:90%;float: left;">' +
                                    '<input type="hidden" class="days" value="'+v.days+'">' +
                                    '<input type="hidden" class="kbxCityId" value="'+v.kbxCityId+'">' +
                                    '<input type="hidden" class="currency" value="'+v.cost.currency+'">' +
                                    '<input type="hidden" class="hotelCostToPrice" value="">' +
                                    '<input type="number" class="layui-input hotelCost" placeholder="请填写成本" value="">' +
                                    '</div>' +
                                    '</th>';
                                hotel_html += '</tr>';
                            });
                        }
                        hotel_html += '</tr><tr>' +
                            '<th>酒店总成本</th>' +
                            '<th colspan="4">' +
                            '<div style="width:5%;float: left;line-height: 50px;">￥</div>' +
                            '<div style="width:92%;float: left;">' +
                            '<input type="text" readonly class="layui-input" id="hotel_total_cost" value="0">' +
                            '</div>' +
                            '</th>' +
                            '</tr>';
                        $("#hotel_body").html(hotel_html);

                        var total_cost = 0;
                        var USD_rate = $("#USD_rate").attr("value");
                        var CAD_rate = $("#CAD_rate").attr("value");
                        var JPY_rate = $("#JPY_rate").attr("value");
                        var ticket_html = '';
                        $.each(ticket_data, function(i, v) {
                            var currSymbol = '￥';
                            var cost = Number(v.sale_price);
                            if(v.currency=='USD'){
                                currSymbol = '$';
                                rate = parseFloat(USD_rate);
                            }else if(v.currency=='JPY'){
                                currSymbol = '円';
                                rate = parseFloat(JPY_rate);
                            }else if(v.currency=='CAD'){
                                currSymbol = 'C$';
                                rate = parseFloat(CAD_rate);
                            }
                            total_cost += cost*rate;

                            ticket_html += '<tr>' +
                                '<th><input type="hidden" class="ticket_id" value="'+v.id+'">'+v.poiname+' - '+v.name+'</th>' +
                                '<th>x1</th>' +
                                '<th>'+currSymbol+' '+v.sale_price+'</th>';
                            ticket_html += '</tr>';
                        });
                        //保留两位小数
                        total_cost = total_cost.toFixed(2);
                        ticket_html += '</tr><tr>' +
                            '<th>门票总成本</th>' +
                            '<th colspan="2">' +
                            '<div style="width:5%;float: left;line-height: 50px;">￥</div>' +
                            '<div style="width:92%;float: left;">' +
                            '<input type="text" readonly class="layui-input" id="ticket_total_cost" value="'+total_cost+'">' +
                            '</div>' +
                            '</th>' +
                            '</tr>';
                        $("#ticket_body").html(ticket_html);

                        setCarPrice();
                    }
                }
            });

            //打开一个弹窗 点击保存触发事件
            layer.open({
                type: 1,
                area: ['95%', '95%'],
                scrollbar: false,
                btn: ['保存', '取消'],
                content: $('#setNewPriceShade'),
                yes: function(index, layero) {
                    var pro_start_day = $('#starttime').val(); //获取开始时间
                    var pro_end_day = $('#endtime').val(); //获取结束时间
                    var log_start_day = $("input[name=nt-starttime]").val();
                    var log_end_day = $("input[name=nt-endtime]").val();
                    var pro_start_time = parseInt(new Date(pro_start_day + ' 00:00:00').getTime());
                    var log_start_time = parseInt(new Date(log_start_day + ' 00:00:00').getTime());
                    var pro_end_time = parseInt(new Date(pro_end_day + ' 23:59:59').getTime());
                    var log_end_time = parseInt(new Date(log_end_day + ' 23:59:59').getTime());
                    if(log_start_time < pro_start_time) {
                        layer.msg('时间段开始时间小于产品上架时间');
                        return false;
                    }
                    if(log_end_time > pro_end_time) {
                        layer.msg('时间段结束时间大于产品下架时间');
                        return false;
                    }
                    if(log_end_time < log_start_time) {
                        layer.msg('结束时间不能小于开始时间');
                        return false;
                    }
                    var time_type = $('input[name=time_type]:checked').val();
                    var month_value = $('input[name=month_value]:checked').val();
                    var time_value = [];
                    if(time_type==0 || time_type==3){
                        time_value = '';
                    }else if(time_type==1){
                        time_value = month_value;
                    }else{
                        var week_value = $("input[name=week]:checked");
                        if(week_value.length<1){
                            layer.msg("请选择日期类型");
                            return false;
                        }else{
                            $.each(week_value,function(i,v){
                                time_value.push($(v).val())
                            });
                            time_value = time_value.join(",");
                        }
                    }
                    //获取筛选的数据
                    var selectDays = getDaysByDates(log_start_day,log_end_day,time_type,time_value);
                    if(time_type==3){
                        selectDays = moreTimeList;
                    }
                    if(selectDays.length < 1){
                        layer.msg("您选择的时间段中没有时间被选择");
                        return false;
                    }

                    var f_cost = $("#5_cost").val();
                    var s_cost = $("#7_cost").val();
                    var t_cost = $("#12_cost").val();

                    if(f_cost>0 && s_cost>0 && t_cost>0){

                    }else{
                        layer.msg("请填写包车价格！");
                        return false;
                    }

                    var more_btn = $("#more_btn").attr("data-id");
                    if(more_btn==1){
                        var error_flag = 0;
                        $(".hotelCost").each(function(){
                            var hotelCost_val = $(this).val();
                            if(hotelCost_val>0){

                            }else{
                                error_flag = 1;
                                return false;
                            }
                        });
                        if(error_flag>0){
                            layer.msg("请填写酒店价格！");
                            return false;
                        }
                    }

                    //保存数据
                    saveVehiclePackageData(package_id,selectDays,moreTimeList);
                }
            });
        });
        //【包车成本】弹窗中时间段选择渲染
        function renderSelectTimeFormNew(){
            $('#selectNewTimeForm').children().remove();
            var str = '<label class="layui-form-label">&nbsp;</label>\n' +
                '                        <div class="layui-input-block layui-col-xs6" style="margin: 0;">\n' +
                '                            <input type="radio" lay-filter="time_type" title="全部" checked name="time_type" value="0" />\n' +
                '                            <input type="radio" lay-filter="time_type" title="按单双日" name="time_type" value="1" />\n' +
                '                            <input type="radio" lay-filter="time_type" title="按星期" name="time_type" value="2" />\n' +
                '                        </div>\n' +
                '                        <div class="layui-input-block layui-col-xs8" id="single" style="margin: 0;display: none;">\n' +
                '                            <input type="radio" lay-filter="month_value" title="每月单日" name="month_value" value="8" />\n' +
                '                            <input type="radio" lay-filter="month_value" title="每月双日" name="month_value" value="9" />\n' +
                '                        </div>\n' +
                '                        <div class="layui-input-block layui-col-xs8" id="week" style="margin: 0;display: none;">\n' +
                '                            <input type="checkbox" lay-skin="primary" lay-filter="xq" title="每周一" class="time_week" name="week" value="1" />\n' +
                '                            <input type="checkbox" lay-skin="primary" lay-filter="xq" title="每周二" class="time_week" name="week" value="2" />\n' +
                '                            <input type="checkbox" lay-skin="primary" lay-filter="xq" title="每周三" class="time_week" name="week" value="3" />\n' +
                '                            <input type="checkbox" lay-skin="primary" lay-filter="xq" title="每周四" class="time_week" name="week" value="4" />\n' +
                '                            <input type="checkbox" lay-skin="primary" lay-filter="xq" title="每周五" class="time_week" name="week" value="5" />\n' +
                '                            <input type="checkbox" lay-skin="primary" lay-filter="xq" title="每周六" class="time_week" name="week" value="6" />\n' +
                '                            <input type="checkbox" lay-skin="primary" lay-filter="xq" title="每周日" class="time_week" name="week" value="0" />\n' +
                '                        </div>\n';
            //增加额外的时间
            $('#selectNewTimeForm').append(str);
        }

        //实时计算
        //酒店成本变动
        function countHotelCost(){
            var USD_rate = $("#USD_rate").attr("value");
            var CAD_rate = $("#CAD_rate").attr("value");
            var JPY_rate = $("#JPY_rate").attr("value");
            var total_cost = 0;
            $(".hotelCost").each(function(){
                var cost = $(this).val();
                if(cost==undefined || cost<=0){
                    return false;
                }
                var currency = $(this).parent().find(".currency").val();
                var days = $(this).parent().find(".days").val();
                days = parseInt(days);
                var final_cost = Number(cost);
                var rate = 1;
                if(currency=='USD'){
                    rate = parseFloat(USD_rate);
                }else if(currency=='CAD'){
                    rate = parseFloat(CAD_rate);
                }else if(currency=='JPY'){
                    rate = parseFloat(JPY_rate);
                }
                final_cost = final_cost*days*rate;
                total_cost += final_cost;

                var hotel_rate = $("#hotel_rate").attr("value");
                hotel_rate = parseFloat(hotel_rate);
                var hotelCostToPrice = final_cost*hotel_rate;
                hotelCostToPrice = Math.ceil(hotelCostToPrice*100)/100;
                $(this).parent().find(".hotelCostToPrice").attr("value",hotelCostToPrice);
            });

            total_cost = Math.ceil(total_cost*100)/100;
            $("#hotel_total_cost").attr("value",total_cost);
        }
        $(document).on("input propertychange",'.hotelCost',function(){
            countHotelCost();
            createSpecs();
        });
        //包车成本变动
        $(document).on("input propertychange",'#5_cost_currency,#7_cost_currency,#12_cost_currency',function(){
            var exchangeNum = $("#exchangeNum").attr("value");
            exchangeNum = parseFloat(exchangeNum);
            var id = $(this).attr("id");
            var value = $(this).val();
            value = Number(value);
            var cny_value = value*exchangeNum;
            cny_value = Math.round(cny_value*100)/100;

            var cost_input;
            if(id=="5_cost_currency"){
                cost_input = $("#5_cost");
            }else if(id=="7_cost_currency"){
                cost_input = $("#7_cost");
            }else if(id=="12_cost_currency"){
                cost_input = $("#12_cost");
            }
            cost_input.attr("value",cny_value);

            createSpecs();
        });
        //根据成本   展示自动生成的规格价格
        function createSpecs(){
            var f_cost = $("#5_cost").val();
            var s_cost = $("#7_cost").val();
            var t_cost = $("#12_cost").val();
            f_cost = Number(f_cost);
            s_cost = Number(s_cost);
            t_cost = Number(t_cost);
            //全部取整
            f_cost = Math.ceil(f_cost);
            s_cost = Math.ceil(s_cost);
            t_cost = Math.ceil(t_cost);
            var hotel_total_cost = $("#hotel_total_cost").val();
            var ticket_total_cost = $("#ticket_total_cost").val();
            var vehicle_rate = $("#vehicle_rate").attr("value");
            var hotel_rate = $("#hotel_rate").attr("value");
            var ticket_rate = $("#ticket_rate").attr("value");

            //存储成本
            var save_vehicle_cost = 0;
            var hotel_vehicle_cost = 0;
            var ticket_vehicle_cost = 0;

            vehicle_rate = parseFloat(vehicle_rate);
            hotel_rate = parseFloat(hotel_rate);
            ticket_rate = parseFloat(ticket_rate);
            //用车价格
            var f_cost_sale = f_cost>0 ? f_cost*vehicle_rate : 0;
            var s_cost_sale = f_cost>0 ? s_cost*vehicle_rate : 0;
            var t_cost_sale = f_cost>0 ? t_cost*vehicle_rate : 0;
            f_cost_sale = Math.ceil(f_cost_sale*100)/100;
            s_cost_sale = Math.ceil(s_cost_sale*100)/100;
            t_cost_sale = Math.ceil(t_cost_sale*100)/100;

            hotel_total_cost = Number(hotel_total_cost);
            hotel_total_cost = hotel_total_cost>0 ? hotel_total_cost : 0;
            var hotel_price = hotel_total_cost>0 ? hotel_total_cost*hotel_rate : 0;
            ticket_total_cost = Number(ticket_total_cost);
            ticket_total_cost = ticket_total_cost>0 ? ticket_total_cost : 0;
            var ticket_price = ticket_total_cost>0 ? ticket_total_cost*ticket_rate : 0;

            hotel_price = Math.ceil(hotel_price*100)/100;
            ticket_price = Math.ceil(ticket_price*100)/100;

            hotel_vehicle_cost = hotel_total_cost>0 ? Math.ceil(hotel_total_cost*100)/100 : 0;
            ticket_vehicle_cost = ticket_total_cost>0 ? Math.ceil(ticket_total_cost*100)/100 : 0;

            var more_btn = $("#more_btn").attr("data-id");
            var html = '';
            var head_html = '';

            if(more_btn==1) {
                //包含酒店&门票
                head_html = '<tr><th>出行类型</th><th>车型</th><th style="width:10%;">最低下单数</th><th style="width:10%;">最小增长数</th><th>【 包车*辆*<span class="redsp">利率</span> + 酒店*间*<span class="redsp">利率</span> + 门票*人*<span class="redsp">利率</span> 】 / 人数</th><th>售卖单价</th></tr>';
                for(var i=1;i<=6;i++){
                    var vehicle_price = 0;
                    var other_price = 0;
                    var text = '【 (';
                    var carType = '';
                    var carTypeCode = 1;
                    if(i<=3){
                        vehicle_price = f_cost_sale;
                        save_vehicle_cost = f_cost;
                        carType = '5座';
                        carTypeCode = 1;
                        text += "<span class='boldsp'>"+f_cost + "</span> x <span class='boldsp'>1</span>辆" + " x <span class='redsp'>" +vehicle_rate;
                    }else if(3<i<=6){
                        vehicle_price = s_cost_sale;
                        save_vehicle_cost = s_cost;
                        carType = '7座';
                        carTypeCode = 10;
                        text += "<span class='boldsp'>"+s_cost + "</span> x <span class='boldsp'>1</span>辆" + " x <span class='redsp'>" +vehicle_rate;
                    }else{
                        vehicle_price = t_cost_sale;
                        save_vehicle_cost = t_cost;
                        carType = '12座';
                        carTypeCode = 20;
                        text += "<span class='boldsp'>"+t_cost + "</span> x <span class='boldsp'>1</span>辆" + " x <span class='redsp'>" +vehicle_rate;
                    }
                    text += "</span>) + (<span class='boldsp'>";

                    if(i<=2){
                        other_price = hotel_price + ticket_price*i;
                        text += hotel_total_cost + "</span> x <span class='boldsp'>1</span>间" + " x <span class='redsp'>" +hotel_rate;
                    }else if(i>2 && i<=4){
                        other_price = hotel_price*2 + ticket_price*i;
                        text += hotel_total_cost + "</span> x <span class='boldsp'>2</span>间" + " x <span class='redsp'>" +hotel_rate;
                    }else{
                        other_price = hotel_price*3 + ticket_price*i;
                        text += hotel_total_cost + "</span> x <span class='boldsp'>3</span>间" + " x <span class='redsp'>" +hotel_rate;
                    }
                    text += "</span>) + (<span class='boldsp'>";

                    text += ticket_total_cost+"</span> x <span class='boldsp'>"+i+"</span>人" + " x <span class='redsp'>" +ticket_rate+"</span>) 】 / "+i;

                    var sale_price = vehicle_price + other_price;
                    sale_price = Math.ceil(sale_price/i);

                    html += '<tr>' +
                        '<th>' +
                        '<input type="hidden" class="people_num" value="'+i+'">' +
                        '<div class="person_name">'+i+'人出行</div>' +
                        '</th>' +
                        '<th><input type="hidden" class="carType" value="'+carTypeCode+'">'+carType+'</th>' +
                        '<th class="minorder_num">'+i+'</th>' +
                        '<th class="inc_order_num">'+i+'</th>' +
                        '<th>'+text+'</th>' +
                        '<th style="width:150px;">' +
                        '<div style="width:10%;float: left;line-height: 40px;">￥</div>' +
                        '<div style="width:85%;float:left;">' +
                        '<input type="hidden" class="vehicle_price" value="'+save_vehicle_cost+'">' +
                        '<input type="hidden" class="hotel_price" value="'+hotel_vehicle_cost+'">' +
                        '<input type="hidden" class="ticket_price" value="'+ticket_vehicle_cost+'">' +
                        '<input type="number" readonly class="layui-input person_price" value="'+sale_price+'">' +
                        '</div>' +
                        '</th>' +
                        '</tr>' +
                        '</tr>';
                }
            }else{
                //纯用车
                head_html = '<tr><th>车型</th><th>成本</th><th>利率</th><th>售卖价格</th></tr>';
                html = '<tr>' +
                    '<th class="person_name">5座车</th>' +
                    '<th>￥ '+f_cost+'</th>' +
                    '<th> x '+vehicle_rate+'</th>' +
                    '<th>' +
                    '<div style="width:5%;float: left;line-height: 40px;">￥</div>' +
                    '<div style="width:92%;float:left;">' +
                    '<input type="hidden" class="carType" value="1">' +
                    '<input type="number" id="5_sale_s" readonly class="layui-input person_price" value="'+f_cost_sale+'" />' +
                    '</div>' +
                    '</th>' +
                    '</tr>' +
                    '<tr>' +
                    '<th class="person_name">7座车</th>' +
                    '<th>￥ '+s_cost+'</th>' +
                    '<th> x '+vehicle_rate+'</th>' +
                    '<th>' +
                    '<div style="width:5%;float: left;line-height: 40px;">￥</div>' +
                    '<div style="width:92%;float: left;">' +
                    '<input type="hidden" class="carType" value="10">' +
                    '<input type="number" id="7_sale_s" readonly class="layui-input person_price" value="'+s_cost_sale+'" />' +
                    '</div>' +
                    '</th>' +
                    '</tr>' +
                    '<tr>' +
                    '<th class="person_name">12座车</th>' +
                    '<th>￥ '+t_cost+'</th>' +
                    '<th> x '+vehicle_rate+'</th>' +
                    '<th>' +
                    '<div style="width:5%;float: left;line-height: 40px;">￥</div>' +
                    '<div style="width:92%;float: left;">' +
                    '<input type="hidden" class="carType" value="20">' +
                    '<input type="number" id="12_sale_s" readonly class="layui-input person_price" value="'+t_cost_sale+'" />' +
                    '</div>' +
                    '</th>' +
                    '</tr>';
            }

            $("#specs_head").html(head_html);
            $("#specs_body").html(html);
        }
        //提交
        function saveVehiclePackageData(package_id,date,more_time){
            //记录数据
            var postData = {};
            var mydata = null;
            var more_btn = $("#more_btn").attr("data-id");//是否为纯包车

            //组装person列表
            var hotels = [];
            var specs = [];
            var personlist = $("#specs_body tr");
            if(more_btn==1){
                $(".hotelCost").each(function(){
                    var hotel = {};
                    hotel.hotelCost = $(this).val();
                    hotel.hotelCostToPrice = $(this).parent().find(".hotelCostToPrice").attr("value");
                    hotels.push(hotel);
                });

                $.each(personlist,function(i,v){
                    var spec = {};
                    spec.num = $(v).find(".people_num").val();
                    spec.name = $(v).find(".person_name").text();
                    spec.carType = $(v).find(".carType").val();
                    spec.minorder_num = $(v).find(".minorder_num").text();
                    spec.inc_order_num = $(v).find(".inc_order_num").text();
                    spec.price = $(v).find(".person_price").val();
                    spec.vehicle_price = $(v).find(".vehicle_price").val();
                    spec.hotel_price = $(v).find(".hotel_price").val();
                    spec.ticket_price = $(v).find(".ticket_price").val();
                    specs.push(spec);
                });
            }else{
                $.each(personlist,function(i,v){
                    var spec = {};
                    spec.num = 1;
                    spec.name = $(v).find(".person_name").text();
                    spec.carType = $(v).find(".carType").val();
                    spec.minorder_num = 1;
                    spec.inc_order_num = 1;
                    spec.person_price = $(v).find(".person_price").val();
                    specs.push(spec);
                });
            }

            postData.specs = specs;
            postData.hotels = hotels;
            postData.date = date;
            //组装时间集合
            postData.package_id = package_id;
            postData.more_time = more_time;
            postData.more_btn = more_btn;
            var param = JSON.stringify(postData);
            var shadowindex = layer.load(1); //添加laoding,0-2两种方式
            $.post("/admin/product/setVehicleProductPrice",{param},function(data){
                layer.close(shadowindex);
                layer.msg(data.msg);
                if(data.code==200){
                    setTimeout(function(){
                        window.location.reload();
                    },1500);
                }
            },'json');
            return mydata;
        }


        //初始化时配置车型派单价
        function setCarPrice(){
            var exchangeNum = $("#exchangeNum").attr("value");
            exchangeNum = parseFloat(exchangeNum);
            var f_cost_currency = $("#5_cost_currency").val();
            var s_cost_currency = $("#7_cost_currency").val();
            var t_cost_currency = $("#12_cost_currency").val();
            f_cost_currency = Number(f_cost_currency);
            s_cost_currency = Number(s_cost_currency);
            t_cost_currency = Number(t_cost_currency);
            var f_cost =  Math.round(f_cost_currency*exchangeNum*100)/100;
            var s_cost =  Math.round(s_cost_currency*exchangeNum*100)/100;
            var t_cost =  Math.round(t_cost_currency*exchangeNum*100)/100;
            $("#5_cost").attr("value",f_cost);
            $("#7_cost").attr("value",s_cost);
            $("#12_cost").attr("value",t_cost);
            createSpecs();
        }


        //酒店门票成本启用&关闭    按钮
        $("#more_btn").click(function(){
            var dataid = $(this).attr("data-id");
            if(dataid==1){
                $(this).attr("data-id",0);
                $(".more_cost_li").hide();
                $(this).addClass("layui-btn-danger");
                $(this).text("未使用");
            }else{
                $(this).attr("data-id",1);
                $(".more_cost_li").show();
                $(this).removeClass("layui-btn-danger");
                $(this).text("启用中");
            }
            createSpecs();

            return false;
        });

    });
</script>
</html>